package com.zhuiyun.project.api.plan.fitnessPlan.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.plan.fitnessPlan.entity.FitnessPlan;
import com.zhuiyun.project.api.plan.fitnessPlan.mapper.FitnessPlanMapper;
import com.zhuiyun.project.api.plan.fitnessPlan.model.FitnessPlanModel;
import com.zhuiyun.project.api.plan.fitnessPlan.service.FitnessPlanService;
import com.zhuiyun.project.api.plan.fitnessPurpose.mapper.FitnessPurposeMapper;
import com.zhuiyun.project.api.plan.fitnessType.entity.FitnessType;
import com.zhuiyun.project.api.plan.fitnessType.service.FitnessTypeService;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName FitnessActionController
 * @Description TODO
 * @Author ys
 * @Date 2023/11/2 8:48
 **/
@RestController
@RequestMapping("/plan")
public class FitnessPlanController {
    @Autowired
    private FitnessPlanService fitnessPlanService;

    @Resource
    FitnessPlanMapper fitnessPlanMapper;
    /**
    * @Author 杨珅
    * @Description todo 健身计划分页查询
    * @Date 2023/11/2 9:28
    * @Return  * @param null
    */
    @PreAuthorize("@ss.hasPermi('plan:fitnessPlan')")
    @ApiOperation(value = "健身计划分页查询")
    @OptLog(modular = "健身计划列表", type = CommonConstants.SELECT, describe = "健身计划分页查询 ")
    @GetMapping("/getFitnessPlan")
    public CommonResult selectAll(PageRequest pageRequest, String fitnessPlanName,String venueUniqueIdentifier,Integer fitnessSeriesId){
        PageResult pageResult = fitnessPlanService.selectAll(pageRequest,fitnessPlanName,venueUniqueIdentifier,fitnessSeriesId);
        return CommonResult.ok(pageResult);
    }
    /**
     * @Author 杨珅
     * @Description todo 根据学院id查询计划
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @PreAuthorize("@ss.hasPermi('plan:fitnessPlan')")
    @ApiOperation(value = "健身计划分页查询")
    @OptLog(modular = "健身计划列表", type = CommonConstants.SELECT, describe = "健身计划分页查询 ")
    @GetMapping("/selectPlanById")
    public CommonResult selectPlanById(@RequestParam Integer memberId){
        return CommonResult.ok(fitnessPlanService.selectPlanById(memberId));
    }
    /**
     * @Author 杨珅
     * @Description todo 健身计划新增
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @PreAuthorize("@ss.hasPermi('plan:fitnessPlan')")
    @ApiOperation(value = "健身计划新增")
    @OptLog(modular = "健身计划列表", type = CommonConstants.ADD, describe = "健身计划新增 ")
    @PostMapping("/addFitnessPlan")
    public CommonResult insertFitnessPlan(@RequestBody FitnessPlanModel fitnessPlan)throws CommonException {
        return CommonResult.ok(fitnessPlanService.insertFitnessPlan(fitnessPlan));
    }
    /**
     * @Author 杨珅
     * @Description todo 健身计划修改
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @PreAuthorize("@ss.hasPermi('plan:fitnessPlan')")
    @ApiOperation(value = "健身计划修改")
    @OptLog(modular = "健身计划列表", type = CommonConstants.UPDATE, describe = "健身计划修改 ")
    @PutMapping("/updateFitnessPlan")
    public CommonResult updateFitnessPlan(@RequestBody FitnessPlan fitnessPlan)throws CommonException{
        return CommonResult.ok(fitnessPlanService.updateFitnessPlan(fitnessPlan));
    }
    /**
     * @Author 杨珅
     * @Description todo 健身计划删除
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @PreAuthorize("@ss.hasPermi('plan:fitnessPlan')")
    @ApiOperation(value = "健身计划删除")
    @OptLog(modular = "健身计划列表", type = CommonConstants.DELETE, describe = "健身计划删除 ")
    @DeleteMapping("/deleteFitnessPlan")
    public CommonResult deleteFitnessPlan(@RequestBody FitnessPlan fitnessPlan){
        return CommonResult.ok(fitnessPlanService.deleteFitnessPlan(fitnessPlan));
    }

    /*
    * @Author xy
    * @Description todo 测试sql拦截器查询
    * @Date 2023/11/30 18:48
    * @Return
    * @param
    */
    @GetMapping("/testplan")
    public CommonResult test(){
        fitnessPlanMapper.selectList(null);
        return CommonResult.ok();
    }
}
